package com.amigo.online.provider.manager.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.amigo.online.common.base.controller.BaseController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.provider.manager.model.entity.MerchantTbl;
import com.amigo.online.provider.manager.result.MerchantTblInfo;
import com.amigo.online.provider.manager.service.MerchantTblService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

@RestController
@RequestMapping(value = "/merchantTbl", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class MerchantTblController extends BaseController {

    @Resource
    private MerchantTblService merchantTblService;

    @PostMapping(value = "/getMerchantTblList")
    public ResponseEntity<Response> getMerchantTblList(@RequestBody MerchantTbl merchantTbl) {

        JSONObject result = new JSONObject();
        // 分页语句
        Page<Object> page = PageHelper.startPage(merchantTbl.getPageNo(), 10);
        List<MerchantTblInfo> merchantTblList = merchantTblService.findMerchantTblList(merchantTbl);
        result.put("merchantTblList", merchantTblList);
        result.put("pagetotal", page.getTotal());
        return success(result);
    }

    @PutMapping(value = "/checkMerchantTbl")
    public ResponseEntity<Response> checkMerchantTbl(@RequestBody MerchantTbl merchantTbl) {
        return success(merchantTblService.checkMerchantTbl(merchantTbl));
    }

    @PutMapping(value = "/deleteMerchantTbl")
    public ResponseEntity<Response> deleteMerchantTbl(@RequestBody MerchantTbl merchantTbl) {
        return success(merchantTblService.deleteMerchantTbl(merchantTbl));
    }


    @PostMapping(value = "/saveMerchantTbl")
    public ResponseEntity<Response> saveMerchantTbl(@RequestBody MerchantTbl merchantTbl) {
        return success(merchantTblService.saveMerchantTbl(merchantTbl));
    }


    @PutMapping(value = "/updateMerchantTbl")
    public ResponseEntity<Response> updateMerchantTbl(@RequestBody MerchantTbl merchantTbl) {
        return success(merchantTblService.updateMerchantTbl(merchantTbl));
    }

    @GetMapping(value = "/updateMerchantTbl/manager/{startId}/{endId}")
    public ResponseEntity<Response> manager(@PathVariable("startId") Long startId, @PathVariable("endId") Long endId) {
        return success(merchantTblService.manager(startId, endId));
    }

}
